Skip to content

fix(analytics): exclude non-CodeMie-owned native sessions from output#410

Open
BolotnyaBoss wants to merge 3 commits into
codemie-ai:mainfrom
BolotnyaBoss:EPMCDME-13367
Open

fix(analytics): exclude non-CodeMie-owned native sessions from output#410
BolotnyaBoss wants to merge 3 commits into
codemie-ai:mainfrom
BolotnyaBoss:EPMCDME-13367

Conversation

@BolotnyaBoss

Copy link
Copy Markdown
Contributor

Summary

Native sessions from bare claude/codex logs that lack CodeMie ownership evidence were only labeled native-external, not excluded — so untracked usage still counted toward analytics totals. SessionsSource now filters them out by default; a new --include-external flag restores the prior unfiltered view for comparison.

Changes

  • sessions-source.ts: drop native sessions tagged native-external unless includeExternal is set.
  • index.ts / types.ts / sources/types.ts: add --include-external CLI flag threaded through AnalyticsOptionsSourceLoadOptions.
  • Add unit tests covering default exclusion, opt-in inclusion, filter ordering, and tracked-session passthrough.
  • Add planning artifacts (spec, plan, technical analysis) from the SDLC workflow used to design this fix.

Testing

  • Tests added/updated (sessions-source.test.ts, 5 new cases)
  • Manual testing done (codemie analytics --last 7d with/without --include-external; confirmed exclusion behavior against real native session logs)

Checklist

  • Code follows project standards
  • CI is green (npm run ci)
  • No merge conflicts with main

EPMCDME-13367

Sviatoslav Likhtarchyk added 2 commits July 7, 2026 16:56
Native sessions tagged native-external by hasOwnershipMarker were only
labeled, not filtered, so untracked claude/codex usage still counted
toward totals. SessionsSource now drops them by default; --include-external
restores the prior unfiltered behavior for comparison.

EPMCDME-13367
Spec, plan, technical analysis, and task run artifacts from the
brainstorming/planning workflow behind the analytics exclusion fix.

EPMCDME-13367
…rnal (EPMCDME-13367)

Two bugs caused CodeMie-managed sessions to lose their ownership marker and
appear as native-external in analytics:

1. Sidecar overwrite on resume: appendTranscriptMarker keyed the sidecar by the
   CodeMie session ID, so resuming with a new Claude session overwrote the prior
   transcript's entry in the ownership index. Fixed by keying the sidecar by the
   Claude session ID (transcript basename without .jsonl) — each Claude session now
   gets its own non-overwriting marker. Write is idempotent; skips if already exists.

2. Empty transcript_path at SessionStart: the transcript file does not exist when
   the SessionStart hook fires, so the marker was never written for the initial
   session. Fixed by calling appendTranscriptMarker on the first UserPromptSubmit/Stop
   event that carries transcript_path (deferred write, idempotent).

Also adds a fallback for sessions started via the native claude CLI (no
CODEMIE_SESSION_ID env var): writes a minimal ownership sidecar from the
SessionStart event and exits cleanly instead of throwing.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants